from fastapi import Query
from typing import Optional


class PaginationQueryParams():
    def __init__(self,
                 page: int = Query(default=1, description="页码"),
                 page_size: int = Query(default=10, description='每页条数', ge=1, le=10)
                 ) -> None:
        self.page = page
        self.page_size = page_size


class UserQueryParams():
    def __init__(self,
                 username: Optional[str] = Query(default=None, description='用户名'),
                 nick_name: Optional[str] = Query(default=None, description='姓名'),
                 is_active: Optional[str] = Query(default=None, description='状态')
                 ) -> None:
        self.username = username
        self.nick_name = nick_name
        self.is_active = None
        if is_active is not None:
            if is_active.lower() == "true":
                self.is_active = True
            elif is_active.lower() == "false":
                self.is_active = False
        print(f"接收到的参数username: {username},nick_name: {nick_name}, is_active: {self.is_active}")

    def to_query_params(self):
        query_params = {}
        for item, value in self.__dict__.items():
            if value is not None:
                if item == 'is_active':
                    query_params.update({'is_active': value})
                else:
                    query_params.update({item + '__icontains': value})
        return query_params


